package com.learn.ThreadPoolLearnTwo;

import org.apache.log4j.Logger;

import java.util.concurrent.TimeUnit;

/**
 * @author ln
 * @Description: ${todo}
 * @date 2020/12/27
 */
public class Testw {
    private static final Logger logger = Logger.getLogger(Testw.class);

    public static void testInterrupt(){
        Thread t1=new Thread(
                ()->{
                    logger.info("enter sleep...");
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        logger.info("wake up...");
                        e.printStackTrace();
                    }
                }
        );
        t1.start();

        try {
            Thread.sleep(1000);
            logger.info("interrupt.....");
            t1.interrupt();//打断t1线程的sleep,会抛出InterruptedException
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();

            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        testInterrupt();
    }
}
